package disjunction.examples.entities
{
	import disjunction.extensions.view.DisplayObjectView;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	
	/**
	 * @author Nick Wiggill
	 */
	
	public class DemoView extends DisplayObjectView
	{
		/*
		public override function initialise(userData:Object):void
		{
			
			
		}
		*/
		protected override function update(timeDeltaMs:uint):void
		{
			var entityModel:DemoEntityModel;
			var entityView:DisplayObject;
			
			for each (entityModel in model_.current)
			{
				entityView = _currentViewsByEntity[entityModel];
				trace('?', entityView);
				entityView.visible = true;
				entityView.x = entityModel.position.x;
				entityView.y = entityModel.position.y;
			}
		}
		
		protected override function createEntity(entity:Object):Object
		{
			var colour:uint;
			
			switch(entity.type)
			{
				case DemoEntityModel.TYPE_BOUNCER: colour = 0xFFFF00; break;
				case DemoEntityModel.TYPE_DANCER: colour = 0x00FF00; break;
				case DemoEntityModel.TYPE_WANDERER: colour = 0x00FFFF; break;
				case DemoEntityModel.TYPE_JITTERER: colour = 0xFF0000; break;
			}
			
			var shape:Shape = new Shape();
			drawSmileyOn(shape, (entity as DemoEntityModel).radius, colour);
			return shape;
		}

		private function drawSmileyOn(shape:Shape, radius:Number, colour:uint):void
		{			
			//face
			shape.graphics.beginFill(colour);
			shape.graphics.drawCircle(0, 0, radius);
			shape.graphics.endFill();
			
			//left eye
			shape.graphics.beginFill(0x000000);
			shape.graphics.drawCircle(-2.5, -2.5, 1);
			shape.graphics.endFill();
			
			//right eye
			shape.graphics.beginFill(0x000000);
			shape.graphics.drawCircle(2.5, -2.5, 1);
			shape.graphics.endFill();
			
			//mouth
			shape.graphics.beginFill(0x000000);
			shape.graphics.lineStyle(1);
			shape.graphics.moveTo(0, 3);
			shape.graphics.lineTo(-3, 2);
			shape.graphics.lineTo(3, 2);
			shape.graphics.endFill();
		}
		
		public function get model_():DemoModel
		{
			return model as DemoModel;
		}
	}
}